import java.util.*;

public class Test {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            Queue<Integer> queue = new LinkedList<>();
            while (a > b) {
                int c = a / b;  //这是商
                int d = a % b;  //这是余数
                queue.offer(d);
                a = c;
            }
            queue.offer(a);
            int size = queue.size();
            int ret = 0;
            for (; size != 0; size--) {
                int val = queue.poll();
                ret = val * (10^(size - 1)) + ret;
            }
            System.out.println(ret);
        }
    }

    public static void main2(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.replaceAll("l", "_"));
        System.out.println(str.replaceFirst("l", "_"));


        String str2 = "helloworld" ;
        System.out.println(str.substring(5));
        System.out.println(str.substring(0, 5));

    }
    public static void main5(String[] args) {
        String ret = "abcd12345ed125ss123456789";
        main1(ret);


    }
    public static void main1(String args) {
        Scanner in = new Scanner(System.in);

        LinkedList<Integer> queue = new LinkedList<>();
        String str = args;
        int[] ret = new int[str.length()];
        // 注意 hasNext 和 hasNextLine 的区别
        //while (in.hasNextLine()) { // 注意 while 处理多个 case
            //String str1 = in.nextLine();



            int i = 0;
            while(i < str.length()) {
                int count1 = queue.size();
                int count = 0;  //每次进来都要把计数器归0
                //如果是数字的话,入队列
                while(i < str.length()) {
                    if(str.charAt(i) < 65) {   //A的asicll码值是65
                        //queue.addLast(Integer.parseInt(tmp);); //这里添加进去的是一个字符 数字
                        String tmp = String.valueOf(str.charAt(i));  //字符先转化为字符串
                        queue.addLast(Integer.parseInt(tmp));       //字符串转化为数字
                        count++;
                        i++;
                    }else {
                        break;
                    }
                }
                //if(str.charAt(i) < 10) {
                //queue.addLast(str.charAt(i));
                //count++;
                if(count <= count1) {
                    //说明队列中的长 不做改变,并把之前的尾插进去的值删掉
                    while(count != 0) {
                        queue.removeLast();
                        count--;
                    }
                }else {
                    //说明新的更长 ， 弹出count1长度的值
                    while(count1 != 0) {
                        queue.removeFirst();
                        count1--;
                    }
                }
                i++;
            }
        //}
        //走到这说明链表中已经存在最长的数字串了
        int j = 0;
        while(!queue.isEmpty()) {
            ret[j] = queue.poll() ;
            j++;
        }
        System.out.print(Arrays.toString(ret));
    }
}
